package com.info.zhiduoduo.repository.mapper.system;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.project.ProjectCategoryTemplateDto;
import com.info.zhiduoduo.repository.dto.system.ProjectCategoryBriefDto;
import com.info.zhiduoduo.repository.dto.system.ProjectCategoryDto;
import com.info.zhiduoduo.repository.entity.system.ProjectTemplate;
import com.info.zhiduoduo.repository.entity.system.SystemProjectcategory;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author TerryJ
 * @since 2018-12-08
 */
public interface ProjectCategoryMapper extends BaseMapper<SystemProjectcategory> {


    @Select("select zsp.projectcategoryid,zsp.projectcategory,childt.childpc from zdd_system_projectcategory zsp " +
            " LEFT JOIN ( select parentid , GROUP_CONCAT(projectcategoryid,\"-\",projectcategory) as childpc from zdd_system_projectcategory GROUP BY parentid) as childt ON childt.parentid = zsp.projectcategoryid" +
            " where zsp.parentid = 0 and zsp.deleted = 0 " +
            "  order by zsp.sort DESC ")
    List<ProjectCategoryBriefDto> queryPorjectCategory();

    @Select(" select pc1.* from zdd_system_projectcategory pc1 where pc1.projectcategoryid = #{categoryid} ")
    SystemProjectcategory getParentCategory(@Param("categoryid") Integer categoryid);

    @Select(" select pc.*,pc2.projectcategory as parentname " +
            " from zdd_system_projectcategory pc " +
            " left join zdd_system_projectcategory pc2 on pc2.projectcategoryid = pc.parentid " +
            " where pc.parentid = #{parentid} and pc.deleted = 0 " +
            "  order by pc.sort DESC ")
    List<ProjectCategoryDto> getcategoryList(Integer parentid);

    @Select(" select pc.*,pc2.projectcategory as parentname " +
            " from zdd_system_projectcategory pc " +
            " left join zdd_system_projectcategory pc2 on pc2.projectcategoryid = pc.parentid " +
            " where pc.parentid > 0 and pc.deleted = 0 ")
    List<ProjectCategoryDto> getAllLevelTwoList();

    @Select(" select projectcategoryid,projectcategory " +
            " from zdd_system_projectcategory pc " +
            " where pc.parentid = 0 " +
            " AND pc.deleted = 0 " +
            " order by pc.sort DESC ")
    List<ProjectCategoryTemplateDto> getProjectCategoryInTemplate();

    @Select(" select * from zdd_project_template " +
            " where categoryid = #{categoryid} and deleted = 0 ")
    List<ProjectTemplate> getProjectTemplate(@Param("categoryid") int categoryid);
}
